#include #include #include #include using std::string; using std::cout; using std::cin; using std::endl; struct FileHeader { char headerField[2]; unsigned int fileSize; unsigned short reserved1; unsigned short reserved2; unsigned int startingAddress; void display(); }; void FileHeader::display() { cout << "Header Field: " << headerField[0] << headerField[1] << endl; cout << "File Size: " << fileSize << endl; cout << "Reserved 1: " << reserved1 << endl; cout << "Reserved 2: " << reserved2 << endl; cout << "Starting Address: " << startingAddress << endl; } struct ImageHeader { unsigned int headerSize; unsigned int width; unsigned int height; unsigned short colorPlanes; unsigned short bitsPerPixel; unsigned int compression; unsigned int imageSize; int horizontalRes; int verticalRes; unsigned int colors; unsigned int importantColors; void display(); }; void ImageHeader::display() { cout << "Header Size: " << headerSize << endl; cout << "Width: " << width << endl; cout << "Height: " << height << endl; cout << "Color Planes: " << colorPlanes << endl; cout << "Bits Per Pixel: " << bitsPerPixel << endl; cout << "Compression: " << compression << endl; cout << "Image Size: " << imageSize << endl; cout << "Horizontal Resolution: " << horizontalRes << endl; cout << "Vertical Resolution: " << verticalRes << endl; cout << "Number of Colors: " << colors << endl; cout << "Important Colors: " << importantColors << endl; } struct Pixel { unsigned char blue; unsigned char green; unsigned char red; }; struct Image { FileHeader fileHeader; ImageHeader imageHeader; Pixel* pixels; Image(char fileName[]); ~Image(); //destructor - clean up function void displayHeaders(); }; Image::~Image() { delete []pixels; } Image::Image(char fileName[]) { std::ifstream fin("Untitled.bmp",std::ios::binary); fin.read(fileHeader.headerField,2); fin.read((char*)&fileHeader.fileSize,4); fin.read((char*)&fileHeader.reserved1,2); fin.read((char*)&fileHeader.reserved2,2); fin.read((char*)&fileHeader.startingAddress,4); fin.read((char*)&imageHeader.headerSize,4); fin.read((char*)&imageHeader.width,4); fin.read((char*)&imageHeader.height,4); fin.read((char*)&imageHeader.colorPlanes,2); fin.read((char*)&imageHeader.bitsPerPixel,2); fin.read((char*)&imageHeader.compression,4); fin.read((char*)&imageHeader.imageSize,4); fin.read((char*)&imageHeader.horizontalRes,4); fin.read((char*)&imageHeader.verticalRes,4); fin.read((char*)&imageHeader.colors,4); fin.read((char*)&imageHeader.importantColors,4); pixels = new Pixel[imageHeader.width * imageHeader.height]; fin.close(); } void Image::displayHeaders() { fileHeader.display(); imageHeader.display(); } void main() { Image image("untitled2.bmp"); image.displayHeaders(); }